<template>
  <div>
    <h1>文件上传和处理系统</h1>
    <input type="file" @change="onFileChange">
    <button @click="uploadFileWord">上传文件</button>
    <input v-model="oldText" placeholder="原文本">
    <input v-model="newText" placeholder="新文本">
    <button @click="processFile">处理文件</button>
    <button @click="downloadFile">下载文件</button>
  </div>
</template>

<script>
import {getClean, uploadFile,updateFile,transFile} from "@/api/module/zxm/room";

export default {
  data() {
    return {
      file: null,
      filePath: '',
      oldText: '',
      newText: '',
      cleanList:[],
      processRequest: {
        filePath: '',
        oldText: '',
        newText: ''
      }
    };
  },
  created() {
   // this.updateForMation();
    this.transWord();
  },
  methods: {
    onFileChange(event) {
      // 获取选择的文件
      //const file = event.target.files[0];
      this.file = event.target.files[0];
      // 可以在这里处理文件，例如读取文件内容、显示文件信息等
      console.log(this.file);
    },
    uploadFileWord() {
      if (this.file) {
        // 将文件上传到后端
        uploadFile(this.file).then(response => {
          this.cleanList = response.data;
        });
      }
    },
    transWord(){
      transFile().then(response => {
        this.cleanList = response.data;
      });
    },

    updateForMation(){
      updateFile().then(response => {
        this.cleanList = response.data;
      });
    },
    // ...
    processFile() {
      // 将 processRequest 对象作为请求的 body 发送给后端
      this.$http.post('/api/process', this.processRequest)
        .then(response => {
          // 处理响应
          // ...
        })
        .catch(error => {
          // 处理错误
          // ...
        });
    }
  }
}
</script>
